var pageNum = 0;
$(function(){
	if(userid == null || userid == ''){
		window.location.href=server_url + '/skuProductNo.do';
		return;
	}
	$("#usersId").val(userid);
	getSkuProductList(pageNum,userid);
})
function toSkuProductAdd() {
	window.location.href="skuProductAdd.do?ran="+Math.random();
	
}
function toSkuProductInfo(id) {
	localStorage.setItem("id", id);
	window.location.href="skuProductInfo.do?ran="+Math.random()+"&id="+id;
}
//分页显示  
function getSkuProductList(value,userid) {
	$.ajax({
		url:server_url+'/rest/product/skuProductList.do?ran='+Math.random()+"&currPage="+value+'&userid='+userid,
		type:'post',
		async:false,
		success:function(data){
			dataRoot = data;
			if(dataRoot != null){
				render($("#skuProductList"),dataRoot);
			}
		}
	});
}
var dataRoot;
function render(parent, data){
	var str="";
	var jsonObj = data.data;
	//console.log(jsonObj);
	if(jsonObj != null && jsonObj.length > 0){
		for (var i=0;i<jsonObj.length;i++) {
			var lr = i%2==0?"fl":"fr";
			str +='<div class="con_box '+lr+'" onclick="toSkuProductInfo(\''+jsonObj[i].id+'\')">\
				<p class="con_tit">'+jsonObj[i].productName+'</p>\
				<p class="con_normal">库存：'+jsonObj[i].overPlusNum+'头</p>\
				<p class="con_normal">售价：<span>¥'+jsonObj[i].price+'/头</span></p>\
				<p class="con_normal">'+jsonObj[i].modifyTime.substring(0,10)+'</p>\
				</div>';
		}
		parent.append(str);
		pageNum++;
	}else{
		window.location.href=server_url + '/skuProductNo.do';
	}
	if($("#loading").length>0){
		$("#loading").css('display','none');
	}
}